<template>
	<view>
		<view class="statbar"></view>
		<u-navbar :title="title" :autoBack="true" rightText="保存" @rightClick="rightClick">
		</u-navbar>
		<view v-if="type==1" style="margin-top: 30px;padding: 20px;">
			<u-input style="background-color: #FFFFFF;" border="bottom" maxlength="20" :value="value" @change="change"></u-input>
			<view class="desc">起个好听的名字吧</view>
		</view>


		<view v-if="type==2" style="margin-top: 40px; ">
			<u-cell-group :border="showBorder">
				<u-cell :border="showBorder" size="large" :clickable="true" class="cell" title="男" @click="value = '男'">
					<view slot="value" class="u-slot-value" v-if="value == '男'">
						<u-icon name="checkbox-mark" size="26" color="#55aa00"></u-icon>
					</view>
				</u-cell>
				<u-line></u-line>
				<u-cell :border="showBorder" size="large" :clickable="true" class="cell" title="女" @click="value = '女'">
					<view slot="value" class="u-slot-value" v-if="value == '女'">
						<u-icon name="checkbox-mark" size="26" color="#55aa00"></u-icon>
					</view>
				</u-cell>
			</u-cell-group>
		</view>
		<view v-if="type==3" style="margin-top: 30px;padding: 20px;">
			<view @click="show=true">
				<u-input  style="background-color: #FFFFFF;" border="bottom" :value="value" :disabled="true"></u-input>
			</view>
			<u-datetime-picker :show="show" v-model="birthday" mode="date" @confirm="confirm"></u-datetime-picker>
		</view>
		<view v-if="type==4" style="margin-top: 30px;padding: 20px;">
			<u-input  style="background-color: #FFFFFF;" border="bottom" :value="value" @change="change"></u-input>
		</view>
		<view v-if="type==5" style="margin-top: 30px;padding: 20px;">
			<u-input  style="background-color: #FFFFFF;" border="bottom" :value="value" @change="change"></u-input>
		</view>
		<view v-if="type==6" style="margin-top: 30px;padding: 20px;">
			<u--textarea  style="background-color: #FFFFFF;" v-model="value" maxlength="20" placeholder="请输入签名内容" @change="change"></u--textarea>
		</view>
		<view v-if="type==7" style="margin-top: 30px;padding: 20px;">
			<u-input  style="background-color: #FFFFFF;" border="bottom" maxlength="20" :value="value" @change="change"></u-input>
		</view>
	</view>
</template>

<script>
	import {
		updateUser
	} from '../../config/api.js';
	export default {
		data() {
			return {
				show: false,
				value: '',
				oldValue: '',
				title: '',
				type: 0,
				showBorder: false,
				birthday: 0,
			}
		},
		onLoad(options) {
			console.log(options)
			this.value = options.value == "null" ? "" : options.value
			this.oldValue = options.value == "null" ? "" : options.value
			this.type = options.type;
			if (this.type == 1) {
				this.title = "更改昵称"
			}
			if (this.type == 2) {
				this.title = "更改性格"
			}
			if (this.type == 3) {
				this.title = "更改出生日期"
				this.birthday = this.value != "undefined" && this.value != '' ? (new Date(this.value).getTime() / 1000) :
					new Date().getTime() / 1000
			}
			if (this.type == 4) {
				this.title = "更改手机号"
			}
			if (this.type == 5) {
				this.title = "更改地区"
			}
			if (this.type == 6) {
				this.title = "更改签名"
			}
			if (this.type == 7) {
				this.title = "填写邀请码"
			}
		},
		methods: {
			change(value) {
				this.value = value
			},
			rightClick() {
				if (this.value == this.oldValue) {
					uni.navigateBack({
						delta: 1
					})
					return
				}
				let user = {
					nickName: this.type == 1 ? this.value : null,
					sex: this.type == 2 ? this.value : null,
					birth: this.type == 3 ? this.value : null,
					phone: this.type == 4 ? this.value : null,
					area: this.type == 5 ? this.value : null,
					usign: this.type == 6 ? this.value : null,
					inviteCode: this.type == 7 ? this.value : null,
				}
				updateUser(user).then((r) => {
					
					console.log("222222222222222222222222222"+r)
					uni.$u.http.get("/user/getUserInfo").then(resp => {
						console.log(resp)
						this.$store.commit('SetUser', resp);
						getApp().globalData.headerChange = true;
						getApp().globalData.nickNameChange = true;
						getApp().globalData.phoneChange = true;
						getApp().globalData.inviteChange = true;
						getApp().globalData.sexChange = true;
						getApp().globalData.areaChange = true;
						getApp().globalData.birthChange = true;
						getApp().globalData.usignChange = true;
						uni.preloadPage({
							url: "/pages/my/my"
						});
						uni.navigateBack({
							delta: 1
						})
					})
				})

			},
			confirm(e) {
				this.show = false
				this.value = uni.$u.timeFormat(e.value, 'yyyy-mm-dd');

			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		font-size: 18px;
		background-color: #e7e7e7,
	}

	.u-collapse-item,
	.cell {
		padding: 10px 25px 10px 25px;
		background-color: #FFFFFF;

	}

	.statbar {
		height: var(--status-bar-height);
		background: #FFFFFF;
	}

	/deep/ .u-navbar__content__right__text {
		font-size: 14px;
		color: #FFFFFF;
		padding: 5px;
		padding-left: 10px;
		padding-right: 10px;
		border-radius: 3px;
		background-color: #04B00F;
	}

	.desc {
		padding: px;
		font-size: 12px;
		color: #999999;
	}
</style>
